package diploma.kisel.modelas.domain;

import static javax.persistence.GenerationType.IDENTITY;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Type;
import org.joda.time.DateTime;

/**
 * Domain class for Project (table - project).
 * 
 * @author Nikolay Kisel
 *
 */
@Entity
@Table(name = "project")
@NamedQueries({
		@NamedQuery(name = "Project.findAll", query = "select p from Project p"),
		@NamedQuery(name = "Project.findById", query = "select p from Project p where p.id = :id"),
		@NamedQuery(name = "Project.findByUser", query = "select p from Project p where p.user = :user")})
public class Project {

	private Integer id;
	private String name;
	private String shortName;
	private String version;
	private DateTime startDate;
	private DateTime finishDate;

	// for many to one mapping
	private User user;

	private Set<Concept> concepts = new HashSet<Concept>();

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id_project")
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "name")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "short_name")
	public String getShortName() {
		return shortName;
	}

	public void setShortName(String shortName) {
		this.shortName = shortName;
	}

	@Column(name = "version")
	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	@Column(name = "date_start")
	@Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime")
	public DateTime getStartDate() {
		return startDate;
	}

	public void setStartDate(DateTime startDate) {
		this.startDate = startDate;
	}

	@Column(name = "date_finish")
	@Type(type = "org.joda.time.contrib.hibernate.PersistentDateTime")
	public DateTime getFinishDate() {
		return finishDate;
	}

	public void setFinishDate(DateTime finishDate) {
		this.finishDate = finishDate;
	}

	@OneToMany(mappedBy = "project", cascade = CascadeType.ALL, orphanRemoval = true)
	public Set<Concept> getConcepts() {
		return concepts;
	}

	public void setConcepts(Set<Concept> concepts) {
		this.concepts = concepts;
	}

	@ManyToOne
	@JoinColumn(name = "id_user")
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Override
	public String toString() {
		return name;
	}	

}
